/**
 * 多个路径管理器
 */
import {SizeRoot} from "./SizeRoot";
import {PathArray, PathInfo} from "./PathInfo";
import {ShapeInfo} from "./ShapeInfo";
import {SinglePath} from "./SinglePath";



class MultiPaths extends SizeRoot {
    _shapeObject: Array<PathInfo> = [];
    get shapeInfo():ShapeInfo {
        let {width, height, _shapeObject} = this;
        return {
            minX: this._minX, minY: this._minY,
            maxX: this._maxX, maxY: this._maxY,
            middle: this.middle, width, height,
            shapes: _shapeObject
        }
    }

    //清除路径
    reset = () => {
        this._shapeObject.splice(0);
        this.ResetSizeRoot();
    }

    //添加路径
    addPath = (path: PathArray, fillColor?:string, strokeColor?:string, closed?: boolean) => {
        if (closed === undefined) closed = false;
        if (fillColor === undefined && strokeColor === undefined) return;
        let sp = new SinglePath(path);
        sp.SetFillColor(fillColor);
        sp.SetStrokeColor(strokeColor);
        sp.closed = closed;

        let {sMinX, sMaxX, sMinY, sMaxY} = sp.GetRangeInfo();

        //当图形还没有显示内容的时候，对最小值最大值重新定义
        if (this._shapeObject.length === 0) {
            this._minX = sMinX; this._maxX = sMaxX;
            this._minY = sMinY; this._maxY = sMaxY;
        }

        if (this._minX > sMinX) this._minX = sMinX;
        if (this._minY > sMinY) this._minY = sMinY;
        if (this._maxX < sMaxX) this._maxX = sMaxX;
        if (this._maxY < sMaxY) this._maxY = sMaxY;

        let pathInfo: PathInfo = sp.GetPathInfo();
        this._shapeObject.push(pathInfo);
    }

    get multiPathInfo(): ShapeInfo {
        return {
            minX: this._minX, maxX: this._maxX,
            minY: this._minY, maxY: this._maxY,
            width: this.width, height: this.height,
            middle: this.middle, shapes: this._shapeObject
        }
    }
}

export {MultiPaths};